package initialize

import (
	"fmt"

	"github.com/go-playground/validator/v10"
	"gitverse.ru/dlc/similarity-compiler/internal/service/compiler"
	"gitverse.ru/dlc/similarity-compiler/pkg/compilers/luajit"
	"gitverse.ru/dlc/similarity-compiler/pkg/errors"
)

type ServicesDeps struct {
	LuaJITCompiler *luajit.Compiler
}

type Services struct {
	CompilerService *compiler.Service
}

func NewServices(deps ServicesDeps) (*Services, errors.Error) {
	if err := validator.New().Struct(deps); err != nil {
		return nil, errors.NewWithError(fmt.Errorf("validate deps: %w", err), errors.ErrInternalError)
	}

	compilerService, err := compiler.New(compiler.Deps{
		LuaJITCompiler: deps.LuaJITCompiler,
	})
	if err != nil {
		return nil, err.Wrap("compiler service")
	}

	return &Services{
		CompilerService: compilerService,
	}, nil
}
